class SparseVector:
    def __init__(self, nums):
        """
        :type nums: List[int]
        """
        self.d = {}
        for index, num in enumerate(nums):
            if num:
                self.d[index] = num

    # Return the dotProduct of two sparse vectors
    def dotProduct(self, vec):
        """
        :type vec: 'SparseVector'
        :rtype: int
        """
        ans = 0
        if len(self.d) < len(vec.d):
            a, b = self.d, vec.d
        else:
            a, b = vec.d, self.d
        for key in a:
            if key in b:
                ans += a[key] * b[key]
        return ans


